<template>
  <div>
    <!-- 顶部 -->
    <div class="approval_top">
      <div>
        <span>标签：</span>
        <el-select v-model="screen.tag" clearable placeholder="全部" @change="getWikiMes(screen)">
          <el-option
            v-for="tItem in tags"
            :key="tItem.tId"
            :label="tItem.tName"
            :value="tItem.tId"
          />
        </el-select>
      </div>
      <div>
        <span>版本：</span>
        <el-select v-model="screen.edition" clearable placeholder="全部" @change="getWikiMes(screen)">
          <el-option
            v-for="eItem in editions"
            :key="eItem.eId"
            :label="eItem.eName"
            :value="eItem.eId"
          />
        </el-select>
      </div>
      <div>
        <span>节点状态：</span>
        <el-select v-model="screen.status" clearable placeholder="所有" @change="getWikiMes(screen)">
          <el-option
            v-for="aItem in wikiStatus"
            :key="aItem.aId"
            :label="aItem.value"
            :value="aItem.aId"
          />
        </el-select>
      </div>
      <div>
        <el-button @click="clear">清空</el-button>
      </div>
    </div>
    <div class="approval_operate">
      <!-- <el-button type="success" size="mini" @click="onSubmit(2)">通过</el-button> -->
      <el-button type="danger" size="mini" @click="onSubmit(1)">删除节点</el-button>
    </div>
    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="wikiMes.slice(pageSize*(pageNo-1),pageSize*pageNo)"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="节点名称" width="150">
        <template slot-scope="scope">{{ scope.row.wName }}</template>
      </el-table-column>
      <el-table-column prop="wLink" label="链接" show-overflow-tooltip width="200" />
      <el-table-column prop="tName" label="标签" show-overflow-tooltip width="80" />
      <el-table-column prop="eName" label="版本" show-overflow-tooltip />
      <el-table-column label="状态" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>
            <el-button type="danger" size="mini" class="viewBtn" @click="delWiki(scope.row.wId)">删除节点</el-button>
            <el-tag v-show="scope.row.approved==1">审批通过</el-tag>
            <el-tag v-show="scope.row.approved==2" type="success">违规删除</el-tag>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="pageNo"
      :page-sizes="[5, 10, 30, 50]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="wikiMes.length"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
import tagApi from '@/api/tags'
import editionApi from '@/api/edition'
import wikiApi from '@/api/wiki'
export default {
  data() {
    return {
      selectTotal: 0,
      pageNo: 1,
      pageSize: 5,
      screen: {},
      wikiStatus: [
        {
          aId: 1,
          value: '审核通过'
        },
        {
          aId: 2,
          value: '违规删除'
        }
      ],
      wikiMes: [],
      multipleSelection: [],
      tags: [],
      editions: []
    }
  },
  created() {
    this.getWikiMes(this.screen)
    this.getTags()
    this.getEdition()
  },
  methods: {
    onSubmit(num) {
      console.log(num)
      console.log(this.multipleSelection)
      this.$message('暂不支持本功能')
    },
    delWiki(wId) {
      console.log(wId)
      wikiApi.delWiki(wId, 2).then(response => {
        console.log(response)
        this.$message({
          message: response.message,
          type: 'success'
        })
        this.getWikiMes(this.screen)
      })
    },
    clear() {
      this.screen = {}
      this.getWikiMes(this.screen)
    },
    handleSizeChange(pageSize) {
      console.log(`每页 ${pageSize} 条`)
      this.pageSize = pageSize
      this.pageNo = 1
      // this.getWikiMes(this.screen)
    },
    handleCurrentChange(pageNo) {
      console.log(`当前页: ${pageNo}`)
      this.pageNo = pageNo
      // this.getWikiMes(this.screen)
    },
    // 截取数组
    getTags() {
      tagApi.getTags().then(response => {
        console.log(response)
        this.tags = response.data
      })
    },
    getEdition() {
      editionApi.getEdition(this.screen).then(response => {
        console.log(response)
        this.editions = response.data
      })
    },
    getWikiMes(screen) {
      console.log(screen)
      wikiApi.getWiki(screen).then(response => {
        console.log(response)
        this.wikiMes = response.data
        // this.selectTotal = response.data.selectTotal
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      console.log(val)
    }
  }
}
</script>
<style lang="scss" scoped>
.approval_top {
  display: flex;
  margin: 10px 0;
}
.approval_top>div {
  margin-right: 20px;
}

.viewBtn {
  margin-right: 10px;
}
.approval_operate {
  margin: 15px 0;
}
</style>
